package com.tourism.config.handler;

/**
 * @Description
 * @Author z
 * @Date 2021-03-04 20:59
 */

import com.tourism.util.ServletUtils;
import com.tourism.util.common.Response;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 登陆失败处理handler
 **/
@Component
public class LoginFailureHandler extends SimpleUrlAuthenticationFailureHandler {

    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {

        //登录失败信息返回
        ServletUtils.render(response, Response.error(exception.getMessage()));
    }

}
